/**
 * @公司:公约树
 * @位置:苏州
 * @Classname KeyPlayRank
 * @Date 2022-06-03 下午 03:46
 * @Created by hanWanLu
 * @auther 中文:韩万路
 */


package com.animeJava.mode;


import com.animeJava.core.AnimeCore;
import com.animeJava.core.EasingData;

import java.util.Map;

/**
 * 动画列队单个动画列队的计算
 */
public class KeyPlayRank {


    private static AnimeCore animeCore = new AnimeCore();   //动画曲线计算
    private Double  inData ;                 //从的数据
    private Double  toData ;                 //到的数据
    private Double  startTime ;              //开始时间获取
    private Double  endTime;                 //结束时间获取
    private int     thisDataIndex;           //当前的数据动画是在第几个过程中计算

    public KeyPlayRank() {
    }

    public KeyPlayRank(Double inData, Double toData, Double startTime, Double endTime , int thisDataIndex) {
        this.inData = inData;
        this.toData = toData;
        this.startTime = startTime;
        this.endTime = endTime;
        this.thisDataIndex = thisDataIndex;
    }

    /**
     * 计算当前是所在时间内的那个值内
     * @param thisPath  当前动画序列的总时间百分比
     * @return  返回如果为空则当前的队列计算完毕
     */
    public Double computedThisData(EasingData easingData , Double thisPath){
        //
        if(startTime == null || endTime == null || inData == null || toData == null){
            return null;
        }


        if( startTime < thisPath && endTime > thisPath){
            double startPath = thisPath - startTime; //开始和结束所需的时间
            double newThisPath = startPath / (endTime - startTime)  ;

            //计算当前帧所在的位置
            Map<String, PositionVarModel> stringPositionVarModelMap = animeCore.core(easingData, newThisPath);
            Double finalPositionY = stringPositionVarModelMap.get("finalPosition").getY();

            double v = inData + (toData - inData) * finalPositionY;
            return v;
        }

        return null;
    }



    public Double getInData() {
        return inData;
    }

    public void setInData(Double inData) {
        this.inData = inData;
    }

    public Double getToData() {
        return toData;
    }

    public void setToData(Double toData) {
        this.toData = toData;
    }

    public Double getStartTime() {
        return startTime;
    }

    public void setStartTime(Double startTime) {
        this.startTime = startTime;
    }

    public Double getEndTime() {
        return endTime;
    }

    public void setEndTime(Double endTime) {
        this.endTime = endTime;
    }

    public static AnimeCore getAnimeCore() {
        return animeCore;
    }

    public static void setAnimeCore(AnimeCore animeCore) {
        KeyPlayRank.animeCore = animeCore;
    }

    public int getThisDataIndex() {
        return thisDataIndex;
    }

    public void setThisDataIndex(int thisDataIndex) {
        this.thisDataIndex = thisDataIndex;
    }
}
